<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.12.0"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>NeuZephyr: nz::nodes::calc::ReshapeNode Class Reference</title>
<link rel="icon" href="NZ_logo2.png" type="image/x-icon" />
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr id="projectrow">
  <td id="projectlogo"><img alt="Logo" src="NZ_logo2.png"/></td>
  <td id="projectalign">
   <div id="projectname">NeuZephyr
   </div>
   <div id="projectbrief">Simple DL Framework</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.12.0 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function() { codefold.init(0); });
/* @license-end */
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li class="current"><a href="annotated.html"><span>Classes</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="annotated.html"><span>Class&#160;List</span></a></li>
      <li><a href="classes.html"><span>Class&#160;Index</span></a></li>
      <li><a href="inherits.html"><span>Class&#160;Hierarchy</span></a></li>
      <li><a href="functions.html"><span>Class&#160;Members</span></a></li>
    </ul>
  </div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function(){ initResizable(false); });
/* @license-end */
</script>
<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><b>nz</b></li><li class="navelem"><a class="el" href="namespacenz_1_1nodes.html">nodes</a></li><li class="navelem"><a class="el" href="namespacenz_1_1nodes_1_1calc.html">calc</a></li><li class="navelem"><a class="el" href="classnz_1_1nodes_1_1calc_1_1_reshape_node.html">ReshapeNode</a></li>  </ul>
</div>
</div><!-- top -->
<div id="doc-content">
<div class="header">
  <div class="summary">
<a href="#pub-methods">Public Member Functions</a> &#124;
<a href="classnz_1_1nodes_1_1calc_1_1_reshape_node-members.html">List of all members</a>  </div>
  <div class="headertitle"><div class="title">nz::nodes::calc::ReshapeNode Class Reference</div></div>
</div><!--header-->
<div class="contents">

<p>Implements tensor shape transformation within a neural network computational graph.  
 <a href="#details">More...</a></p>
<div class="dynheader">
Inheritance diagram for nz::nodes::calc::ReshapeNode:</div>
<div class="dyncontent">
<div class="center"><img src="classnz_1_1nodes_1_1calc_1_1_reshape_node__inherit__graph.png" border="0" usemap="#anz_1_1nodes_1_1calc_1_1_reshape_node_inherit__map" alt="Inheritance graph"/></div>
<map name="anz_1_1nodes_1_1calc_1_1_reshape_node_inherit__map" id="anz_1_1nodes_1_1calc_1_1_reshape_node_inherit__map">
<area shape="rect" title="Implements tensor shape transformation within a neural network computational graph." alt="" coords="5,80,207,107"/>
<area shape="rect" href="classnz_1_1nodes_1_1_node.html" title="Base class for nodes in a neural network or computational graph." alt="" coords="47,5,165,32"/>
<area shape="poly" title=" " alt="" coords="109,48,109,80,103,80,103,48"/>
</map>
<center><span class="legend">[<a href="graph_legend.html">legend</a>]</span></center></div>
<div class="dynheader">
Collaboration diagram for nz::nodes::calc::ReshapeNode:</div>
<div class="dyncontent">
<div class="center"><img src="classnz_1_1nodes_1_1calc_1_1_reshape_node__coll__graph.png" border="0" usemap="#anz_1_1nodes_1_1calc_1_1_reshape_node_coll__map" alt="Collaboration graph"/></div>
<map name="anz_1_1nodes_1_1calc_1_1_reshape_node_coll__map" id="anz_1_1nodes_1_1calc_1_1_reshape_node_coll__map">
<area shape="rect" title="Implements tensor shape transformation within a neural network computational graph." alt="" coords="39,96,241,123"/>
<area shape="rect" href="classnz_1_1nodes_1_1_node.html" title="Base class for nodes in a neural network or computational graph." alt="" coords="5,5,123,32"/>
<area shape="poly" title=" " alt="" coords="87,42,131,94,127,97,83,46"/>
<area shape="rect" href="classnz_1_1data_1_1_dimension.html" title="Represents a multi &#45; dimensional shape, typically used in deep learning for tensor dimensions." alt="" coords="147,5,285,32"/>
<area shape="poly" title=" " alt="" coords="197,46,153,97,149,94,193,42"/>
</map>
<center><span class="legend">[<a href="graph_legend.html">legend</a>]</span></center></div>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="pub-methods" name="pub-methods"></a>
Public Member Functions</h2></td></tr>
<tr class="memitem:adb97b80637a53a9e1b9776f8fcae8ed7" id="r_adb97b80637a53a9e1b9776f8fcae8ed7"><td class="memItemLeft" align="right" valign="top">&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="#adb97b80637a53a9e1b9776f8fcae8ed7">ReshapeNode</a> (<a class="el" href="classnz_1_1nodes_1_1_node.html">Node</a> *input, const <a class="el" href="classnz_1_1data_1_1_dimension.html">Tensor::shape_type</a> &amp;newShape)</td></tr>
<tr class="memdesc:adb97b80637a53a9e1b9776f8fcae8ed7"><td class="mdescLeft">&#160;</td><td class="mdescRight">Constructs a <a class="el" href="classnz_1_1nodes_1_1calc_1_1_reshape_node.html" title="Implements tensor shape transformation within a neural network computational graph.">ReshapeNode</a> object to reshape the input tensor.  <br /></td></tr>
<tr class="separator:adb97b80637a53a9e1b9776f8fcae8ed7"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a8f9c9e9dbbe4db8d9420b9928ab369f1" id="r_a8f9c9e9dbbe4db8d9420b9928ab369f1"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="#a8f9c9e9dbbe4db8d9420b9928ab369f1">forward</a> () override</td></tr>
<tr class="memdesc:a8f9c9e9dbbe4db8d9420b9928ab369f1"><td class="mdescLeft">&#160;</td><td class="mdescRight">Performs the forward pass operation of the <a class="el" href="classnz_1_1nodes_1_1calc_1_1_reshape_node.html" title="Implements tensor shape transformation within a neural network computational graph.">ReshapeNode</a>.  <br /></td></tr>
<tr class="separator:a8f9c9e9dbbe4db8d9420b9928ab369f1"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a28c90cc1c5dd3837dcbde0c1abc841d5" id="r_a28c90cc1c5dd3837dcbde0c1abc841d5"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="#a28c90cc1c5dd3837dcbde0c1abc841d5">backward</a> () override</td></tr>
<tr class="memdesc:a28c90cc1c5dd3837dcbde0c1abc841d5"><td class="mdescLeft">&#160;</td><td class="mdescRight">Performs the backward propagation for the <a class="el" href="classnz_1_1nodes_1_1calc_1_1_reshape_node.html" title="Implements tensor shape transformation within a neural network computational graph.">ReshapeNode</a>.  <br /></td></tr>
<tr class="separator:a28c90cc1c5dd3837dcbde0c1abc841d5"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="inherit_header pub_methods_classnz_1_1nodes_1_1_node"><td colspan="2" onclick="javascript:dynsection.toggleInherit('pub_methods_classnz_1_1nodes_1_1_node')"><img src="closed.png" alt="-"/>&#160;Public Member Functions inherited from <a class="el" href="classnz_1_1nodes_1_1_node.html">nz::nodes::Node</a></td></tr>
<tr class="memitem:a687ee9c34eb61f8f28caa201ca42696e inherit pub_methods_classnz_1_1nodes_1_1_node" id="r_a687ee9c34eb61f8f28caa201ca42696e"><td class="memItemLeft" align="right" valign="top">virtual void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classnz_1_1nodes_1_1_node.html#a687ee9c34eb61f8f28caa201ca42696e">print</a> (std::ostream &amp;os) const</td></tr>
<tr class="memdesc:a687ee9c34eb61f8f28caa201ca42696e inherit pub_methods_classnz_1_1nodes_1_1_node"><td class="mdescLeft">&#160;</td><td class="mdescRight">Prints the type, data, and gradient of the node.  <br /></td></tr>
<tr class="separator:a687ee9c34eb61f8f28caa201ca42696e inherit pub_methods_classnz_1_1nodes_1_1_node"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a9b85913e12422bb4ac2fff483427bb47 inherit pub_methods_classnz_1_1nodes_1_1_node" id="r_a9b85913e12422bb4ac2fff483427bb47"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classnz_1_1nodes_1_1_node.html#a9b85913e12422bb4ac2fff483427bb47">dataInject</a> (Tensor::value_type *data, bool grad=false) const</td></tr>
<tr class="memdesc:a9b85913e12422bb4ac2fff483427bb47 inherit pub_methods_classnz_1_1nodes_1_1_node"><td class="mdescLeft">&#160;</td><td class="mdescRight">Injects data into a relevant tensor object, optionally setting its gradient requirement.  <br /></td></tr>
<tr class="separator:a9b85913e12422bb4ac2fff483427bb47 inherit pub_methods_classnz_1_1nodes_1_1_node"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a609f1730085dd1d31e0ddcbbae48a065 inherit pub_methods_classnz_1_1nodes_1_1_node" id="r_a609f1730085dd1d31e0ddcbbae48a065"><td class="memTemplParams" colspan="2">template&lt;typename Iterator &gt; </td></tr>
<tr class="memitem:a609f1730085dd1d31e0ddcbbae48a065 inherit pub_methods_classnz_1_1nodes_1_1_node"><td class="memTemplItemLeft" align="right" valign="top">void&#160;</td><td class="memTemplItemRight" valign="bottom"><a class="el" href="classnz_1_1nodes_1_1_node.html#a609f1730085dd1d31e0ddcbbae48a065">dataInject</a> (Iterator begin, Iterator end, const bool grad=false) const</td></tr>
<tr class="memdesc:a609f1730085dd1d31e0ddcbbae48a065 inherit pub_methods_classnz_1_1nodes_1_1_node"><td class="mdescLeft">&#160;</td><td class="mdescRight">Injects data from an iterator range into the output tensor of the InputNode, optionally setting its gradient requirement.  <br /></td></tr>
<tr class="separator:a609f1730085dd1d31e0ddcbbae48a065 inherit pub_methods_classnz_1_1nodes_1_1_node"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:af8b4bab3271df92ca1f0914f7a97b1e8 inherit pub_methods_classnz_1_1nodes_1_1_node" id="r_af8b4bab3271df92ca1f0914f7a97b1e8"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classnz_1_1nodes_1_1_node.html#af8b4bab3271df92ca1f0914f7a97b1e8">dataInject</a> (const std::initializer_list&lt; Tensor::value_type &gt; &amp;data, bool grad=false) const</td></tr>
<tr class="memdesc:af8b4bab3271df92ca1f0914f7a97b1e8 inherit pub_methods_classnz_1_1nodes_1_1_node"><td class="mdescLeft">&#160;</td><td class="mdescRight">Injects data from a std::initializer_list into the output tensor of the <a class="el" href="classnz_1_1nodes_1_1_node.html" title="Base class for nodes in a neural network or computational graph.">Node</a>, optionally setting its gradient requirement.  <br /></td></tr>
<tr class="separator:af8b4bab3271df92ca1f0914f7a97b1e8 inherit pub_methods_classnz_1_1nodes_1_1_node"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><p>Implements tensor shape transformation within a neural network computational graph. </p>
<p>The <code><a class="el" href="classnz_1_1nodes_1_1calc_1_1_reshape_node.html" title="Implements tensor shape transformation within a neural network computational graph.">ReshapeNode</a></code> class modifies the dimensional structure of input tensors while preserving their underlying data. This node enables flexible tensor shape adaptation between different network layers without altering the actual data values.</p>
<p>Core functionality and behavior:</p><ul>
<li><b>Shape Transformation</b>: Reorganizes tensor dimensions according to specified new_shape.</li>
<li><b>Data Preservation</b>: Maintains original data values and memory sharing where possible.</li>
<li><b>Zero-Copy Optimization</b>: Avoids data duplication when compatible memory layouts allow.</li>
<li><b>Gradient Propagation</b>: Correctly routes gradients during backward pass by preserving original tensor dimensions in gradient computations.</li>
<li><b>Runtime Validation</b>: Verifies shape compatibility (total element count) during forward pass.</li>
</ul>
<p>Implementation specifics:</p><ul>
<li><b>Forward Pass</b>: Adjusts tensor dimensions immediately without data movement.</li>
<li><b>Backward Pass</b>: Restores gradient tensor dimensions to match original input shape.</li>
<li><b>Memory Management</b>: Shares underlying data buffer between input and output tensors.</li>
<li><b>CUDA Support</b>: Maintains device context (CPU/GPU) during reshape operations.</li>
</ul>
<p>Typical applications:</p><ul>
<li>Bridging fully connected layers with convolutional layers requiring specific tensor shapes.</li>
<li>Adapting variable-length sequence inputs to fixed-dimension layer requirements.</li>
<li>Implementing dynamic computational graphs with shape-modifying operations.</li>
</ul>
<p>Critical considerations:</p><ul>
<li><b>Element Count Consistency</b>: Input and new_shape must contain identical total elements.</li>
<li><b>Memory Layout Impact</b>: Reshape success depends on tensor memory continuity in some frameworks.</li>
<li><b>Gradient Integrity</b>: Requires maintaining original input shape reference for correct backpropagation.</li>
<li><b>Device Consistency</b>: Input tensor and new_shape must reside on same computation device.</li>
</ul>
<dl class="section note"><dt>Note</dt><dd><ul>
<li>Shape modification doesn't alter tensor data ordering - elements follow memory layout order.</li>
<li>For discontinuous tensors, reshape may trigger implicit data copy (implementation-dependent).</li>
<li>Gradient computation requires preserving original input tensor dimensions throughout node lifetime.</li>
</ul>
</dd></dl>
<dl class="section see"><dt>See also</dt><dd><a class="el" href="classnz_1_1nodes_1_1_node.html" title="Base class for nodes in a neural network or computational graph.">Node</a> Base class for computational <a class="el" href="namespacenz_1_1graph.html" title="Contains classes and functions for managing and executing computation graphs in deep learning workflo...">graph</a> <a class="el" href="namespacenz_1_1nodes.html" title="Contains classes and functionality for nodes in a neural network or computational graph.">nodes</a> </dd>
<dd>
<a class="el" href="classnz_1_1data_1_1_tensor.html#a877f9f2704e39100142d81d289ddc3f2" title="Reshapes the tensor to the specified shape.">Tensor::reshape()</a> Underlying tensor shape modification method</dd></dl>
<h3><a class="anchor" id="autotoc_md105"></a>
Usage Demonstration:</h3>
<div class="fragment"><div class="line"><span class="comment">// Create input node with 4D tensor</span></div>
<div class="line">InputNode input({2, 3, 4, 5}, <span class="keyword">true</span>); <span class="comment">// Batch 2, 3x4x5 features</span></div>
<div class="line"> </div>
<div class="line"><span class="comment">// Reshape to 2D tensor (batch size, flattened features)</span></div>
<div class="line"><a class="code hl_class" href="classnz_1_1nodes_1_1calc_1_1_reshape_node.html">ReshapeNode</a> reshape(&amp;input, {2, 1, 1, 3*4*5});</div>
<div class="line">reshape.<a class="code hl_function" href="#a8f9c9e9dbbe4db8d9420b9928ab369f1">forward</a>();</div>
<div class="line"> </div>
<div class="line"><span class="comment">// Verify new shape</span></div>
<div class="line">std::cout &lt;&lt; <span class="stringliteral">&quot;Reshaped tensor dimensions: &quot;</span></div>
<div class="line">          &lt;&lt; reshape.output-&gt;shape() &lt;&lt; std::endl;</div>
<div class="line"> </div>
<div class="line"><span class="comment">// Backward pass demonstration</span></div>
<div class="line">reshape.backward();</div>
<div class="ttc" id="aclassnz_1_1nodes_1_1calc_1_1_reshape_node_html"><div class="ttname"><a href="classnz_1_1nodes_1_1calc_1_1_reshape_node.html">nz::nodes::calc::ReshapeNode</a></div><div class="ttdoc">Implements tensor shape transformation within a neural network computational graph.</div><div class="ttdef"><b>Definition</b> <a href="_nodes_8cuh_source.html#l03344">Nodes.cuh:3344</a></div></div>
<div class="ttc" id="aclassnz_1_1nodes_1_1calc_1_1_reshape_node_html_a8f9c9e9dbbe4db8d9420b9928ab369f1"><div class="ttname"><a href="#a8f9c9e9dbbe4db8d9420b9928ab369f1">nz::nodes::calc::ReshapeNode::forward</a></div><div class="ttdeci">void forward() override</div><div class="ttdoc">Performs the forward pass operation of the ReshapeNode.</div><div class="ttdef"><b>Definition</b> <a href="_nodes_8cu_source.html#l00559">Nodes.cu:559</a></div></div>
</div><!-- fragment --><dl class="section author"><dt>Author</dt><dd>Mgepahmge (<a href="https://github.com/Mgepahmge">https://github.com/Mgepahmge</a>)</dd></dl>
<dl class="section date"><dt>Date</dt><dd>2023/10/15 </dd></dl>

<p class="definition">Definition at line <a class="el" href="_nodes_8cuh_source.html#l03344">3344</a> of file <a class="el" href="_nodes_8cuh_source.html">Nodes.cuh</a>.</p>
</div><h2 class="groupheader">Constructor &amp; Destructor Documentation</h2>
<a id="adb97b80637a53a9e1b9776f8fcae8ed7" name="adb97b80637a53a9e1b9776f8fcae8ed7"></a>
<h2 class="memtitle"><span class="permalink"><a href="#adb97b80637a53a9e1b9776f8fcae8ed7">&#9670;&#160;</a></span>ReshapeNode()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">nz::nodes::calc::ReshapeNode::ReshapeNode </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="classnz_1_1nodes_1_1_node.html">Node</a> *</td>          <td class="paramname"><span class="paramname"><em>input</em></span>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const <a class="el" href="classnz_1_1data_1_1_dimension.html">Tensor::shape_type</a> &amp;</td>          <td class="paramname"><span class="paramname"><em>newShape</em></span>&#160;)</td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Constructs a <a class="el" href="classnz_1_1nodes_1_1calc_1_1_reshape_node.html" title="Implements tensor shape transformation within a neural network computational graph.">ReshapeNode</a> object to reshape the input tensor. </p>
<p>This constructor initializes a <a class="el" href="classnz_1_1nodes_1_1calc_1_1_reshape_node.html" title="Implements tensor shape transformation within a neural network computational graph.">ReshapeNode</a> with an input node and a new shape. It checks if the number of dimensions of the input tensor's shape matches the number of dimensions of the new shape. If they match, it adds the input node to the list of inputs, creates a new output tensor with the specified new shape and the same requiresGrad property as the input tensor, and sets the node type to "Reshape".</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">input</td><td>A pointer to the input node. Memory location: host - to - device (used to access input tensor information). </td></tr>
    <tr><td class="paramname">newShape</td><td>A reference to the new shape of type <code>Tensor::shape_type</code>. Memory location: host - to - device (used to define the new shape).</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>None</dd></dl>
<p><b>Memory Management Strategy</b>:</p><ul>
<li>The <code>inputs</code> vector stores a pointer to the input node. The memory management of the input node is assumed to be handled by the caller.</li>
<li>The <code>output</code> member variable is a <code>std::shared_ptr</code> to a new <code>Tensor</code> object. The memory of the <code>Tensor</code> will be automatically managed by the <code>std::shared_ptr</code>.</li>
</ul>
<p><b>Exception Handling Mechanism</b>:</p><ul>
<li>Throws <code>std::invalid_argument</code> if the number of dimensions of the input tensor's shape does not match the number of dimensions of the new shape.</li>
</ul>
<p><b>Relationship with Other Components</b>:</p><ul>
<li>Depends on the <code>input</code> node to access its output tensor.</li>
<li>Creates a new <code>Tensor</code> object for the output.</li>
</ul>
<dl class="exception"><dt>Exceptions</dt><dd>
  <table class="exception">
    <tr><td class="paramname">std::invalid_argument</td><td>When the number of dimensions of the input tensor's shape and the new shape do not match.</td></tr>
  </table>
  </dd>
</dl>
<dl class="section note"><dt>Note</dt><dd><ul>
<li>Ensure that the input node is valid and points to a non - null <code><a class="el" href="classnz_1_1nodes_1_1_node.html" title="Base class for nodes in a neural network or computational graph.">Node</a></code> object.</li>
<li>Ensure that the new shape has the same number of dimensions as the input tensor's shape to avoid exceptions.</li>
</ul>
</dd></dl>
<div class="fragment"><div class="line">```cpp</div>
<div class="line"><a class="code hl_class" href="classnz_1_1nodes_1_1_node.html">Node</a>* inputNode = <span class="keyword">new</span> <a class="code hl_class" href="classnz_1_1nodes_1_1_node.html">Node</a>();</div>
<div class="line"><a class="code hl_class" href="classnz_1_1data_1_1_dimension.html">Tensor::shape_type</a> newShape = {1, 2, 3, 4};</div>
<div class="line"><span class="keywordflow">try</span> {</div>
<div class="line">    <a class="code hl_class" href="classnz_1_1nodes_1_1calc_1_1_reshape_node.html">ReshapeNode</a> reshapeNode(inputNode, newShape);</div>
<div class="line">} <span class="keywordflow">catch</span> (<span class="keyword">const</span> std::exception&amp; e) {</div>
<div class="line">    std::cerr &lt;&lt; e.what() &lt;&lt; std::endl;</div>
<div class="line">}</div>
<div class="line">```</div>
<div class="ttc" id="aclassnz_1_1data_1_1_dimension_html"><div class="ttname"><a href="classnz_1_1data_1_1_dimension.html">nz::data::Dimension</a></div><div class="ttdoc">Represents a multi - dimensional shape, typically used in deep learning for tensor dimensions.</div><div class="ttdef"><b>Definition</b> <a href="_dimension_8cuh_source.html#l00057">Dimension.cuh:57</a></div></div>
<div class="ttc" id="aclassnz_1_1nodes_1_1_node_html"><div class="ttname"><a href="classnz_1_1nodes_1_1_node.html">nz::nodes::Node</a></div><div class="ttdoc">Base class for nodes in a neural network or computational graph.</div><div class="ttdef"><b>Definition</b> <a href="_nodes_8cuh_source.html#l00114">Nodes.cuh:114</a></div></div>
</div><!-- fragment --> 
<p class="definition">Definition at line <a class="el" href="_nodes_8cu_source.html#l00550">550</a> of file <a class="el" href="_nodes_8cu_source.html">Nodes.cu</a>.</p>
<div class="dynheader">
Here is the call graph for this function:</div>
<div class="dyncontent">
<div class="center"><img src="classnz_1_1nodes_1_1calc_1_1_reshape_node_adb97b80637a53a9e1b9776f8fcae8ed7_cgraph.png" border="0" usemap="#aclassnz_1_1nodes_1_1calc_1_1_reshape_node_adb97b80637a53a9e1b9776f8fcae8ed7_cgraph" alt=""/></div>
<map name="aclassnz_1_1nodes_1_1calc_1_1_reshape_node_adb97b80637a53a9e1b9776f8fcae8ed7_cgraph" id="aclassnz_1_1nodes_1_1calc_1_1_reshape_node_adb97b80637a53a9e1b9776f8fcae8ed7_cgraph">
<area shape="rect" title="Constructs a ReshapeNode object to reshape the input tensor." alt="" coords="5,5,176,48"/>
<area shape="rect" href="classnz_1_1data_1_1_dimension.html#a073622bb031999163987ccf77f8edfb2" title="Calculates the total number of elements in the Dimension object." alt="" coords="224,5,362,48"/>
<area shape="poly" title=" " alt="" coords="176,24,208,24,208,29,176,29"/>
</map>
</div>

</div>
</div>
<h2 class="groupheader">Member Function Documentation</h2>
<a id="a28c90cc1c5dd3837dcbde0c1abc841d5" name="a28c90cc1c5dd3837dcbde0c1abc841d5"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a28c90cc1c5dd3837dcbde0c1abc841d5">&#9670;&#160;</a></span>backward()</h2>

<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">void nz::nodes::calc::ReshapeNode::backward </td>
          <td>(</td>
          <td class="paramname"><span class="paramname"><em></em></span></td><td>)</td>
          <td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">override</span><span class="mlabel">virtual</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>Performs the backward propagation for the <a class="el" href="classnz_1_1nodes_1_1calc_1_1_reshape_node.html" title="Implements tensor shape transformation within a neural network computational graph.">ReshapeNode</a>. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">None</td><td></td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>None</dd></dl>
<p>This function is responsible for performing the backward propagation in the <a class="el" href="classnz_1_1nodes_1_1calc_1_1_reshape_node.html" title="Implements tensor shape transformation within a neural network computational graph.">ReshapeNode</a>. If the output of the first input tensor requires gradient computation, it copies the gradient of the output tensor to the gradient of the first input tensor's output. The memory copy operation is performed using the CUDA stream manager with a device-to-device memory transfer.</p>
<p>Memory management strategy: The function does not allocate or free any memory. It only copies existing memory using CUDA's memcpy. Exception handling mechanism: There is no explicit exception handling in this function. However, CUDA's memcpy operation may throw errors if there are issues with the memory pointers or the CUDA device.</p>
<dl class="section note"><dt>Note</dt><dd><ul>
<li>Ensure that the CUDA device is properly initialized before calling this function.</li>
<li>The sizes of the output tensor and the first input tensor's output must match for the memory copy to be valid.</li>
</ul>
</dd></dl>
<div class="fragment"><div class="line">```cpp</div>
<div class="line"><a class="code hl_class" href="classnz_1_1nodes_1_1calc_1_1_reshape_node.html">ReshapeNode</a> node;</div>
<div class="line"><span class="comment">// Assume inputs and output tensors are properly initialized</span></div>
<div class="line">node.<a class="code hl_function" href="#a28c90cc1c5dd3837dcbde0c1abc841d5">backward</a>();</div>
<div class="line">```</div>
<div class="ttc" id="aclassnz_1_1nodes_1_1calc_1_1_reshape_node_html_a28c90cc1c5dd3837dcbde0c1abc841d5"><div class="ttname"><a href="#a28c90cc1c5dd3837dcbde0c1abc841d5">nz::nodes::calc::ReshapeNode::backward</a></div><div class="ttdeci">void backward() override</div><div class="ttdoc">Performs the backward propagation for the ReshapeNode.</div><div class="ttdef"><b>Definition</b> <a href="_nodes_8cu_source.html#l00565">Nodes.cu:565</a></div></div>
</div><!-- fragment --><dl class="section author"><dt>Author</dt><dd>Mgepahmge(<a href="https://github.com/Mgepahmge">https://github.com/Mgepahmge</a>)</dd></dl>
<dl class="section date"><dt>Date</dt><dd>2024/07/15 </dd></dl>

<p>Implements <a class="el" href="classnz_1_1nodes_1_1_node.html#a0a9ecbaa3d790ba38e8218aca7837fd0">nz::nodes::Node</a>.</p>

<p class="definition">Definition at line <a class="el" href="_nodes_8cu_source.html#l00565">565</a> of file <a class="el" href="_nodes_8cu_source.html">Nodes.cu</a>.</p>
<div class="dynheader">
Here is the call graph for this function:</div>
<div class="dyncontent">
<div class="center"><img src="classnz_1_1nodes_1_1calc_1_1_reshape_node_a28c90cc1c5dd3837dcbde0c1abc841d5_cgraph.png" border="0" usemap="#aclassnz_1_1nodes_1_1calc_1_1_reshape_node_a28c90cc1c5dd3837dcbde0c1abc841d5_cgraph" alt=""/></div>
<map name="aclassnz_1_1nodes_1_1calc_1_1_reshape_node_a28c90cc1c5dd3837dcbde0c1abc841d5_cgraph" id="aclassnz_1_1nodes_1_1calc_1_1_reshape_node_a28c90cc1c5dd3837dcbde0c1abc841d5_cgraph">
<area shape="rect" title="Performs the backward propagation for the ReshapeNode." alt="" coords="5,39,176,81"/>
<area shape="rect" href="classnz_1_1cu_strm_1_1_stream_manager.html#ab4b2eb422e0e1ee44bdfdc0eb94457ce" title="Returns a reference to the singleton instance of the StreamManager." alt="" coords="224,5,409,48"/>
<area shape="poly" title=" " alt="" coords="176,45,208,40,208,45,177,50"/>
<area shape="rect" href="classnz_1_1cu_strm_1_1_stream_manager.html#afa38d5c6db0e6b48c8f74ce8ad0df2bc" title="Asynchronously copies data between CUDA device and host memory based on the specified memory copy kin..." alt="" coords="224,72,409,115"/>
<area shape="poly" title=" " alt="" coords="177,70,208,75,208,80,176,75"/>
<area shape="rect" href="classnz_1_1cu_strm_1_1_stream_manager.html#a1de1cf3aadea137faf90a2f9b4b7abe2" title="Acquires CUDA stream from pool using round&#45;robin scheduling." alt="" coords="457,39,642,81"/>
<area shape="poly" title=" " alt="" coords="409,77,441,73,442,78,410,83"/>
<area shape="rect" href="classnz_1_1cu_strm_1_1_stream_manager.html#adb1078a67c6e38932d7d58c2adb05ec0" title="Synchronizes CUDA stream execution until data writes complete." alt="" coords="457,105,642,148"/>
<area shape="poly" title=" " alt="" coords="410,104,442,109,441,114,409,109"/>
</map>
</div>

</div>
</div>
<a id="a8f9c9e9dbbe4db8d9420b9928ab369f1" name="a8f9c9e9dbbe4db8d9420b9928ab369f1"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a8f9c9e9dbbe4db8d9420b9928ab369f1">&#9670;&#160;</a></span>forward()</h2>

<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">void nz::nodes::calc::ReshapeNode::forward </td>
          <td>(</td>
          <td class="paramname"><span class="paramname"><em></em></span></td><td>)</td>
          <td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">override</span><span class="mlabel">virtual</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>Performs the forward pass operation of the <a class="el" href="classnz_1_1nodes_1_1calc_1_1_reshape_node.html" title="Implements tensor shape transformation within a neural network computational graph.">ReshapeNode</a>. </p>
<p>This function copies the data from the output tensor of the input node to the output tensor of the <a class="el" href="classnz_1_1nodes_1_1calc_1_1_reshape_node.html" title="Implements tensor shape transformation within a neural network computational graph.">ReshapeNode</a> using CUDA memory copy. It uses the singleton instance of <code><a class="el" href="classnz_1_1cu_strm_1_1_stream_manager.html" title="Centralized CUDA stream and resource management system with automatic dependency tracking.">cuStrm::StreamManager</a>&lt;float&gt;</code> to manage the CUDA stream for the memory copy operation.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">None</td><td></td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>None</dd></dl>
<p><b>Memory Management Strategy</b>:</p><ul>
<li>The function relies on the CUDA memory copy operation (<code>cudaMemcpyDeviceToDevice</code>). The source and destination memory are managed by the <code>Tensor</code> objects (<code>inputs[0]-&gt;output</code> and <code>output</code>).</li>
<li>The CUDA memory copy operation is assumed to handle the actual data transfer and memory allocation/deallocation related to the transfer properly.</li>
</ul>
<p><b>Exception Handling Mechanism</b>:</p><ul>
<li>If the CUDA memory copy operation fails, it may return a CUDA error code. However, this function does not handle CUDA errors explicitly. Callers should check the CUDA error state after calling this function if necessary.</li>
</ul>
<p><b>Relationship with Other Components</b>:</p><ul>
<li>Depends on the <code><a class="el" href="classnz_1_1cu_strm_1_1_stream_manager.html" title="Centralized CUDA stream and resource management system with automatic dependency tracking.">cuStrm::StreamManager</a>&lt;float&gt;</code> singleton to manage the CUDA stream for the memory copy.</li>
<li>Relies on the <code>inputs[0]-&gt;output</code> tensor for the source data and the <code>output</code> tensor for the destination data.</li>
</ul>
<dl class="exception"><dt>Exceptions</dt><dd>
  <table class="exception">
    <tr><td class="paramname">None</td><td>explicitly, but CUDA errors may occur during the memory copy operation.</td></tr>
  </table>
  </dd>
</dl>
<dl class="section note"><dt>Note</dt><dd><ul>
<li>Ensure that the CUDA runtime environment is properly initialized before calling this function.</li>
<li>The CUDA memory copy operation assumes that the source and destination memory regions are valid and have sufficient space.</li>
<li>The time complexity of this function is mainly determined by the CUDA memory copy operation, which is typically proportional to the size of the data being copied (O(n), where n is the number of elements in the output tensor).</li>
</ul>
</dd></dl>
<div class="fragment"><div class="line">```cpp</div>
<div class="line"><span class="comment">// Assume ReshapeNode, Node, and Tensor are defined</span></div>
<div class="line"><a class="code hl_class" href="classnz_1_1nodes_1_1_node.html">Node</a>* inputNode = <span class="keyword">new</span> <a class="code hl_class" href="classnz_1_1nodes_1_1_node.html">Node</a>();</div>
<div class="line"><a class="code hl_class" href="classnz_1_1data_1_1_dimension.html">Tensor::shape_type</a> newShape = {1, 2, 3, 4};</div>
<div class="line"><a class="code hl_class" href="classnz_1_1nodes_1_1calc_1_1_reshape_node.html">ReshapeNode</a> reshapeNode(inputNode, newShape);</div>
<div class="line">reshapeNode.forward();</div>
<div class="line">```</div>
</div><!-- fragment --> 
<p>Implements <a class="el" href="classnz_1_1nodes_1_1_node.html#a8a828c2e91a4aa2a9ab7b94554e4685b">nz::nodes::Node</a>.</p>

<p class="definition">Definition at line <a class="el" href="_nodes_8cu_source.html#l00559">559</a> of file <a class="el" href="_nodes_8cu_source.html">Nodes.cu</a>.</p>
<div class="dynheader">
Here is the call graph for this function:</div>
<div class="dyncontent">
<div class="center"><img src="classnz_1_1nodes_1_1calc_1_1_reshape_node_a8f9c9e9dbbe4db8d9420b9928ab369f1_cgraph.png" border="0" usemap="#aclassnz_1_1nodes_1_1calc_1_1_reshape_node_a8f9c9e9dbbe4db8d9420b9928ab369f1_cgraph" alt=""/></div>
<map name="aclassnz_1_1nodes_1_1calc_1_1_reshape_node_a8f9c9e9dbbe4db8d9420b9928ab369f1_cgraph" id="aclassnz_1_1nodes_1_1calc_1_1_reshape_node_a8f9c9e9dbbe4db8d9420b9928ab369f1_cgraph">
<area shape="rect" title="Performs the forward pass operation of the ReshapeNode." alt="" coords="5,39,176,81"/>
<area shape="rect" href="classnz_1_1cu_strm_1_1_stream_manager.html#ab4b2eb422e0e1ee44bdfdc0eb94457ce" title="Returns a reference to the singleton instance of the StreamManager." alt="" coords="224,5,409,48"/>
<area shape="poly" title=" " alt="" coords="176,45,208,40,208,45,177,50"/>
<area shape="rect" href="classnz_1_1cu_strm_1_1_stream_manager.html#afa38d5c6db0e6b48c8f74ce8ad0df2bc" title="Asynchronously copies data between CUDA device and host memory based on the specified memory copy kin..." alt="" coords="224,72,409,115"/>
<area shape="poly" title=" " alt="" coords="177,70,208,75,208,80,176,75"/>
<area shape="rect" href="classnz_1_1cu_strm_1_1_stream_manager.html#a1de1cf3aadea137faf90a2f9b4b7abe2" title="Acquires CUDA stream from pool using round&#45;robin scheduling." alt="" coords="457,39,642,81"/>
<area shape="poly" title=" " alt="" coords="409,77,441,73,442,78,410,83"/>
<area shape="rect" href="classnz_1_1cu_strm_1_1_stream_manager.html#adb1078a67c6e38932d7d58c2adb05ec0" title="Synchronizes CUDA stream execution until data writes complete." alt="" coords="457,105,642,148"/>
<area shape="poly" title=" " alt="" coords="410,104,442,109,441,114,409,109"/>
</map>
</div>

</div>
</div>
<hr/>The documentation for this class was generated from the following files:<ul>
<li>D:/Users/Mgepahmge/Documents/C Program/NeuZephyr/include/NeuZephyr/<a class="el" href="_nodes_8cuh_source.html">Nodes.cuh</a></li>
<li>D:/Users/Mgepahmge/Documents/C Program/NeuZephyr/src/<a class="el" href="_nodes_8cu_source.html">Nodes.cu</a></li>
</ul>
</div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by&#160;<a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.12.0
</small></address>
</div><!-- doc-content -->
</body>
</html>
